home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / sort / Source / notif.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.2 KB  |  115 lines  |  [TEXT/MPS ]

  1. #include <string.h>
  2. #include <Events.h>
  3. #include <Resources.h>
  4. #include <Memory.h>
  5. #include <ToolUtils.h>
  6. #include <SysEqu.h>
  7. #include <Notification.h>
  8.  
  9. #include "notif.h"
  10. #include "sortWindow.h"
  11.  
  12.  
  13. #define SICN_ID 128
  14. #define NM_STRS 128
  15.  
  16. #define SEND_AGAIN_TIME 5L*60L*60L
  17.  
  18. static pascal void nmResponce(NMRecPtr notif);
  19.  
  20. Boolean gInBackground;
  21.  
  22. void send_Message(short id)
  23. {
  24.     Str255 notiftext;
  25.     NMRec notif;
  26.     long len1, len2;
  27.     NMProcPtr            responseProcPtr = (NMProcPtr)nmResponce;
  28.  
  29.  
  30.     notif.qType = nmType;
  31.     notif.nmMark = 0;
  32.     notif.nmIcon = GetResource('SICN', SICN_ID);
  33.     HLock(notif.nmIcon);
  34.     HNoPurge(notif.nmIcon);
  35.  
  36.     notif.nmSound = (Handle)-1;
  37.     
  38.     notif.nmStr = notiftext;
  39.     notif.nmResp = responseProcPtr;
  40.     notif.nmRefCon = 0L;
  41.  
  42.     GetIndString(notiftext, NM_STRS, id); 
  43.     len1 = *notiftext;
  44.     len2 = *(Ptr)CurApName;
  45.     if ((len1 + len2) > 255) {
  46.         len1 = 255-len2;
  47.     }
  48.     BlockMove(notiftext, notiftext + len2, len1 + 1);
  49.     BlockMove((Ptr)CurApName, notiftext, len2 + 1);
  50.     *notiftext = (len1 + len2) & 0xFF;
  51.  
  52.     
  53.     NMInstall(¬if);
  54.  
  55.     do {
  56.         HandleEvent();
  57.     } while (notif.nmRefCon == 0L);
  58.     HandleEvent();
  59.     HandleEvent();
  60.     HandleEvent();
  61. }
  62.  
  63. static pascal void nmResponce(NMRecPtr notif)
  64. {
  65.     notif->nmRefCon = TickCount();
  66.     NMRemove(notif);
  67. }
  68.  
  69.  
  70. void wait_Foreground(short id)
  71. {
  72.     Str255 notiftext;
  73.     NMRec notif;
  74.     long len1, len2;
  75.     NMProcPtr            responseProcPtr = (NMProcPtr)nmResponce;
  76.  
  77.     notif.qType = nmType;
  78.     notif.nmMark = 1;
  79.     notif.nmIcon = GetResource('SICN', SICN_ID);
  80.     HLock(notif.nmIcon);
  81.     HNoPurge(notif.nmIcon);
  82.  
  83.     notif.nmSound = (Handle)-1;
  84.     notif.nmStr = notiftext;
  85.     notif.nmResp = responseProcPtr;
  86.     notif.nmRefCon = 0L;
  87.  
  88.     GetIndString(notiftext,NM_STRS, id); 
  89.     len1 = *notiftext;
  90.     len2 = *(Ptr)CurApName;
  91.     if ((len1 + len2) > 255) {
  92.         len1 = 255-len2;
  93.     }
  94.     BlockMove(notiftext, notiftext + len2, len1 + 1);
  95.     BlockMove((Ptr)CurApName, notiftext, len2 + 1);
  96.     *notiftext = (len1 + len2) & 0xFF;
  97.     NMInstall(¬if);
  98.     
  99.     do {
  100.         HandleEvent();
  101.         if ((notif.nmRefCon != 0) && 
  102.                 ((TickCount() - notif.nmRefCon)>SEND_AGAIN_TIME)) {
  103.             notif.nmSound = (Handle)-1;
  104.             notif.nmStr = notiftext;
  105.             notif.nmResp = responseProcPtr;
  106.             notif.nmRefCon = 0L;
  107.             NMInstall(¬if);
  108.         }
  109.     } while (gInBackground);
  110.     
  111.     HandleEvent();
  112.     HandleEvent();
  113.     HandleEvent();
  114. }
  115.